package com.azxc.rapid.plus.system.service.impl;

import com.azxc.rapid.core.mp.base.BaseServiceImpl;
import com.azxc.rapid.core.tool.utils.BeanUtil;
import com.azxc.rapid.plus.system.entity.UserRegionEntity;
import com.azxc.rapid.plus.system.excel.UserRegionExcel;
import com.azxc.rapid.plus.system.mapper.UserRegionMapper;
import com.azxc.rapid.plus.system.service.IUserRegionService;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Objects;

/**
 * 服务实现类
 */
@Service
public class UserRegionServiceImpl extends BaseServiceImpl<UserRegionMapper, UserRegionEntity> implements IUserRegionService {
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void importUserRegion(List<UserRegionExcel> data, Boolean isCovered) {
		data.forEach(userRegionExcel -> {
			UserRegionEntity userRegion = Objects.requireNonNull(BeanUtil.copy(userRegionExcel, UserRegionEntity.class));
			this.submit(userRegion);
		});
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public boolean submit(UserRegionEntity entity) {
		return save(entity);
	}

	@Override
	public List<UserRegionExcel> exportUserRegion(Wrapper<UserRegionEntity> queryWrapper) {
		List<UserRegionExcel> userRegionList = baseMapper.exportUserRegion(queryWrapper);
		return userRegionList;
	}

	@Override
	public UserRegionEntity selectUserRegion(Long userId) {
		return baseMapper.selectRegionCode(userId);
	}
}
